package com.huiguo.methodargument.controller;

import com.huiguo.methodargument.config.UserInfo;
import com.huiguo.methodargument.dto.InvokeResult;
import com.huiguo.methodargument.dto.command.LoginCommand;
import com.huiguo.methodargument.dto.command.UserCommand;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Pattern;
import java.util.Map;

@Validated
@RestController
@RequestMapping("/test")
public class TestController {

    @GetMapping("/send_code/{mobile}")
    public InvokeResult<Void> sendCode(@PathVariable @Pattern(regexp = "^1\\d{10}$", message = "手机号格式不对") String mobile) {
        return InvokeResult.success();
    }

    @PostMapping("/login")
    public InvokeResult<Void> login(@RequestBody @Validated LoginCommand loginCommand) {
        return InvokeResult.success();
    }

    @PostMapping("/save")
    public InvokeResult<Void> save(@RequestBody @Validated UserCommand userCommand) {
        return InvokeResult.success();
    }

    /**
     * 自定义参数解析测试方法
     * @param map
     * @return
     */
    @GetMapping("/user")
    public InvokeResult<Void> getUser(@UserInfo Map map) {
        System.out.println("用户名:" + map.get("name"));
        return InvokeResult.success();
    }
}
